<?php
class ManageAction extends BaseAction {
	public function modify() {
		$this->display();
	}
	
	public function edit() {
		header ( 'Content-type:text/html;charset=utf-8' );
		$Dao = M ( "Admin" ); // 实例化模型类
		
		$admin = $Dao->getByAdminName ( $_SESSION['admin']['admin_name'] );
		if($admin['admin_pwd'] != md5($_POST['oldpwd'])) 
			echo "<script language=\"javascript\">alert('密码错误！');window.history.back();</script>";
		else {	
			$update['admin_pwd'] = md5($_POST['newpwd']);
			$condition['admin_id'] = $admin['admin_id'];
			$result = $Dao->where($condition)->save($update);
			if($result)
				echo "<script language=\"javascript\">alert('修改成功！');window.location.href='../Index/main'</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
	}
	
	public function account() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Admin = M ("admin");
		$adminlist = $Admin->order("admin_id")->select();
		for($i=0;$i<count($adminlist);$i++) {
			if($adminlist[$i]["admin_state"]==0) $list[$i]["admin_state_cn"]="禁用";
			else $adminlist[$i]["admin_state_cn"]="正常";
		}
		
		$this->assign('adminlist',$adminlist);
		$this->display();
	}
	
	public function delete() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Admin = M ("admin");
		$condition['admin_id'] = $_GET['id'];
		$result = $Admin->where($condition)->delete();
		if($result)
			echo "<script language=\"javascript\">alert('删除成功！');window.location.href='../../account';</script>";
		else 
			$this->error ( '数据写入错误！请重试...' );
	}
}